<?php
// app\net2023dev\应用下的公共函数文件
//  2023-7-2

// header_remove("X-Powered-By"); //删除响应头


//当前页面信息
function com_pathinfo()
{
    return "TO:" . request()->pathinfo(); //当前页面信息
}
// 生成guid 唯一识别码
if (function_exists('com_guid')) {
    return com_guid(); //已定义
} else {
    function com_guid()
    {
        // 输出格式：
        // $var = [
        //     "salt:" => "462F545598BE255976CA5A7D9A901DA7",
        //     "salt_length:" => 32,
        //     "salt_any" => "462F-98BE-2559-76CA-5A7D",
        //     "salt_any_length:" => 24
        // ];
        mt_srand((float)time() * 10000);
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45); //"-"
        $uuid = substr($charid, 0, 4) . $hyphen
            . substr($charid, 8, 4) . $hyphen
            . substr($charid, 12, 4) . $hyphen
            . substr($charid, 16, 4) . $hyphen
            . substr($charid, 20, 4);
        $salt_any = [
            "salt:" => $charid,
            "salt_length:" => strlen($charid),
            "salt_any" => $uuid,
            "salt_any_length:" => strlen($uuid),
        ];
        return $salt_any;
    }
}
//curl封装
if (!function_exists('com_curl')) {
    function com_curl($url)
    {
        $headerArray = array("Content-type:application/json;", "Accept:application/json");
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        $output = json_decode($output, true);
        return $output;
    }
}

// dump(com_pathinfo());
